package com.hontech.bv.conn.api

import com.hontech.bv.conn.Proto
import com.hontech.bv.conn.SerialPortMod
import com.hontech.bv.conn.serial.Uint16
import com.hontech.bv.conn.serial.Uint8

object Powder {

    suspend fun updownCtrl(type: Int) {
        SerialPortMod.request(
            Proto.REQ_POWDER_UPDOWN_CTRL,
            Proto.ID_POWDER,
            arrayOf(Uint8(type))
        ).assert("测试升降")
    }

    suspend fun dumpCtrl(type: Int) {
        SerialPortMod.request(
            Proto.REQ_POWDER_DUMP_CTRL,
            Proto.ID_POWDER,
            arrayOf(Uint8(type))
        ).assert("测试倾倒")
    }

    suspend fun moveCtrl(position: Int) {
        SerialPortMod.request(
            Proto.REQ_POWDER_MOVE_CTRL,
            Proto.ID_POWDER,
            arrayOf(Uint16(position))
        ).assert("移动倾倒")
    }

    suspend fun cargoCtrl(position: Int) {
        SerialPortMod.request(
            Proto.REQ_POWDER_CARGO_CTRL,
            Proto.ID_POWDER,
            arrayOf(Uint16(position))
        ).assert("货架测试")
    }

    suspend fun pdeCtrl(type: Int) {
        SerialPortMod.request(
            Proto.REQ_POWDER_PDE_CTRL,
            Proto.ID_POWDER,
            arrayOf(Uint8(type))
        ).assert("测试压紧电磁铁")
    }

    suspend fun init() {
        SerialPortMod.request(
            Proto.REQ_POWDER_INIT,
            Proto.ID_POWDER,
            arrayOf()
        ).assert("初始化")
    }

    suspend fun pick(col: Int, waterMl: Int, temp: Int) {
        SerialPortMod.request(
            Proto.REQ_POWDER_PICK,
            Proto.ID_POWDER,
            arrayOf(Uint8(col), Uint8(waterMl), Uint8((temp)))
        ).assert("取货")
    }
}
